#ifndef SERVERSOCKET_H
#define SERVERSOCKET_H

#include <QObject>
#include <QtNetwork>

#define SERVER_PORT 45454
#define SERVER_ID "srvId"


class ServerSocket : public QObject
{
    Q_OBJECT

    Q_PROPERTY(bool udpOnly READ UdpOnly WRITE setUdpOnly)

public:
    explicit ServerSocket(QObject *parent = 0);
    ~ServerSocket();

    bool UdpOnly();
    void setUdpOnly(bool);


private:
    void timerEvent(QTimerEvent *);
    void broadcast();
    void writeLog(QString log);
    QString findServerAddress();

signals:
    void serverLog(QString log);
    void clientConnected(QString address, int port);

private slots:
    void establishClientConnection();
    void readClientTcpData();
    void networkUpdated();
    void udpGetData();
    void startNetwork();


public slots:
    void start();
    void stop();
    void sendToClient(QString msg);


private:
    QNetworkConfigurationManager* iNetworkManager;
    QUdpSocket* iUdpBroadcastSocket;
    QTcpServer* iTcpServer;
    QTcpSocket* iClientCommSocket;
    int iTimerId;

    QNetworkSession* iNetworkSession;
    bool udpOnly;
    QString iServerAddress;

    bool iWantedToStart;


};

#endif // SERVERSOCKET_H
